# -*- coding:utf-8 -*-
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
class Solution:
    # 返回从上到下每个节点值列表，例：[1,2,3]
    def PrintFromTopToBottom(self, root):
        # write code here
        # if not root:
        #     return []
        # stack = [root.val]
        # def helper(stack, *root):
        #     # print('test')
        #     root_list = list(root)
        #     if not len(root_list) or list(set(root_list))[0] == None:
        #         return False
        #     new_stack = []
        #     for one_root in root_list:
        #         if one_root:
        #             if one_root.left:
        #                 stack.append(one_root.left.val)
        #                 new_stack.append(one_root.left)
        #             if one_root.right:
        #                 stack.append(one_root.right.val)
        #                 new_stack.append(one_root.right)
        #             # print(stack)
        #     helper(stack, *new_stack)
        # helper(stack, root)
        # return stack
        queue = []
        list = []
        if not root:
            return []
        queue.append(root)
        while queue:
            tmp = queue.pop(0)
            if tmp.left:
                queue.append(tmp.left)
            if tmp.right:
                queue.append(tmp.right)
            list.append(tmp.val)
        return list

